package com.example.xjt.restful;

/**
 * 英文-返回码-枚举
 * <p>
 * （PS：为什么不把 ResultCodeEnum 和 ResultCodeEngEnum 写在一起？
 * 因为实际需求开发中可能会让你的API适配 zh-CN zh-TW en-US 等等多种其他语言
 * 若是把这些语言的msg都放一个枚举里，耦合太强，改动时可能会出现误删等情况，
 * 而且随着语言越来愈多，单个枚举值的语言属性会越来越多，不便维护
 * ）
 */
public enum ResultCodeEngEnum {
    SUCCESS(0, "Operation is successful"),
    CLIENT_IS_NOT_EXIST(1101, "The client does not exist"),
    TOKEN_IS_INVALID(1102, "Token is invalid"),
    VERITY_GEN_ERROR(9801, " Verification code generation failed "),
    VERITY_IDENTITY_ERROR(9803, " Verification code failed "),
    TOKEN_NULL(9777, "no token in header "),
    TOKEN_TIME_OUT(9776, "Token expired, please log in again "),
    TOKEN_USER_ALREADY_SIGN(9775, "Token user logged in, please log out and request this interface again "),
    LOGOUT_FAILED(2201, " Exit failed "),
    FAILED(9500, "response FAILED "),
    BUSY(9600, "system BUSY "),
    ACCOUNT_PASS_FAILED(9301, "password error "),
    ACCOUNT_NOT_EXIST(9302, "user name does not exist "),
    ACCOUNT_DISABLED(9303, "User has no permissions/disabled "),
    NOT_LOGIN(9403, " not logged in "),
    REQ_BODY_IS_NULL(9995, " missing requestBody requestBody"),
    VALIDATE_FAILED(9996, "error "),
    ARITHMETIC_FAILED(9997, "arithmetic exception "),
    ARRAY_INDEX_OUT_OF_BOUNDS_FAILED(9998, "Array out-of-bounds exception "),
    USER_IS_USING(7701, " target user in use "),
    ERROR(9999, "unknown ERROR "),

    BAD_REQUEST(400, "error request "),
    UNAUTHORIZED(401," UNAUTHORIZED "),
    FORBIDDEN(403," Being rejected "),
    NOT_FOUND(404," resource not found "),
    UNSUPPORTED_MEDIA_TYPE(415," Unsupported media type "),


    BIZ_ERROR(5001, "business error "),
    BIZ_ERROR_1(500101, "Business error 1"),
    BIZ_ERROR_2(500102, "Service error 2");

    private int code;
    private String message;

    /**
     * 根据code，返回对应的英文message
     *
     * @param code resultCode码
     * @return String 对应的英文message
     */
    public static String getEngMsgByCode(int code) {
        for (ResultCodeEngEnum engEnum : ResultCodeEngEnum.values()) {
            if (engEnum.getCode() == code) {
                return engEnum.getMessage();
            }
        }
        return ResultCodeEngEnum.ERROR.getMessage();
    }

    ResultCodeEngEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }


    public String getMessage() {
        return message;
    }



}
